package Views;

import Controllers.ItemCTR;
import Models.*;
import Views.TableModels.ItemTableModel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JOptionPane;

/**
 * @author Thomas
 */
public class ItemView extends javax.swing.JFrame implements WindowListener
{
	private ItemCTR controller = new ItemCTR();
	private Supplier supplierTemp = null;
	private SupplierPicker sp = null;

	public ItemView()
	{
		initComponents();
		findTable.addMouseListener(new MouseAdapter(){
			@Override
			public void mouseClicked(MouseEvent e){
				if (e.getClickCount() == 2)
				{
					if(findTable.getSelectedRowCount() == 1)
					{
						int chosenId = Integer.parseInt(findTable.getValueAt(findTable.getSelectedRow(), 0).toString());
						new ItemInfoView(controller.getItem(chosenId)).setVisible(true);
					}
				}
			}
		 });
	}

	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        addLocationBG = new javax.swing.ButtonGroup();
        findLocationBG = new javax.swing.ButtonGroup();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        stockTabbedPane = new javax.swing.JTabbedPane();
        addStockPanel = new javax.swing.JPanel();
        addDescriptionLabel = new javax.swing.JLabel();
        addNameLabel = new javax.swing.JLabel();
        addNameTF = new javax.swing.JTextField();
        addManufacturerLabel = new javax.swing.JLabel();
        addManufacturerTF = new javax.swing.JTextField();
        addSupplierLabel = new javax.swing.JLabel();
        addSupplierTF = new javax.swing.JTextField();
        addFindSupplierButton = new javax.swing.JButton();
        addShowSupplierButton = new javax.swing.JButton();
        addItemDescriptionLabel = new javax.swing.JLabel();
        addItemDescriptionTA1 = new javax.swing.JScrollPane();
        addDescriptionTA = new javax.swing.JTextArea();
        addPriceLabel = new javax.swing.JLabel();
        addPriceSP = new javax.swing.JSpinner();
        addLocationLabel = new javax.swing.JLabel();
        addLumberYardRB = new javax.swing.JRadioButton();
        addHardwareStoreRB = new javax.swing.JRadioButton();
        addStockLabel = new javax.swing.JLabel();
        addMinStockLabel = new javax.swing.JLabel();
        addMinStockSP = new javax.swing.JSpinner();
        addMaxStockLabel = new javax.swing.JLabel();
        addMaxStockSP = new javax.swing.JSpinner();
        addAddButton = new javax.swing.JButton();
        addPriceLabel1 = new javax.swing.JLabel();
        findStockPanel = new javax.swing.JPanel();
        findDescriptionLabel = new javax.swing.JLabel();
        findNameLabel = new javax.swing.JLabel();
        findNameTF = new javax.swing.JTextField();
        findManufacturerLabel = new javax.swing.JLabel();
        findManufacturerTF = new javax.swing.JTextField();
        findSupplierLabel = new javax.swing.JLabel();
        findSupplierTF = new javax.swing.JTextField();
        findFindSupplierButton = new javax.swing.JButton();
        findShowSupplierButton = new javax.swing.JButton();
        findPriceLabel = new javax.swing.JLabel();
        findPriceSP = new javax.swing.JSpinner();
        findPriceLabel1 = new javax.swing.JLabel();
        findLumberYardRB = new javax.swing.JRadioButton();
        findHardwareStoreRB = new javax.swing.JRadioButton();
        findStockLabel = new javax.swing.JLabel();
        findMinStockLabel = new javax.swing.JLabel();
        findMinStockSP = new javax.swing.JSpinner();
        findMaxStockLabel = new javax.swing.JLabel();
        findMaxStockSP = new javax.swing.JSpinner();
        findFindButton = new javax.swing.JButton();
        showAllButton = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        findTable = new javax.swing.JTable();
        getStockPanel = new javax.swing.JPanel();
        getDescriptionLabel = new javax.swing.JLabel();
        getIdLabel = new javax.swing.JLabel();
        getIdSp = new javax.swing.JSpinner();
        getButton = new javax.swing.JButton();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Lager");

        addDescriptionLabel.setText("Her kan der tilføjes varer til lageret");

        addNameLabel.setText("Navn:");

        addManufacturerLabel.setText("Producent:");

        addSupplierLabel.setText("Leverandør: ");

        addSupplierTF.setEnabled(false);

        addFindSupplierButton.setText("Find");
        addFindSupplierButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addFindSupplierButtonActionPerformed(evt);
            }
        });

        addShowSupplierButton.setText("Info");
        addShowSupplierButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addShowSupplierButtonActionPerformed(evt);
            }
        });

        addItemDescriptionLabel.setText("Beskrivelse:");

        addDescriptionTA.setColumns(20);
        addDescriptionTA.setRows(5);
        addItemDescriptionTA1.setViewportView(addDescriptionTA);

        addPriceLabel.setText("Pris:");

        addLocationLabel.setText("Afdeling:");

        addLocationBG.add(addLumberYardRB);
        addLumberYardRB.setText("Trælasthandel");

        addLocationBG.add(addHardwareStoreRB);
        addHardwareStoreRB.setText("Byggemarked");

        addStockLabel.setText("Lager:");

        addMinStockLabel.setText("Min.");

        addMaxStockLabel.setText("Max.");

        addAddButton.setText("Tilføj");
        addAddButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addAddButtonActionPerformed(evt);
            }
        });

        addPriceLabel1.setText("kr.");

        org.jdesktop.layout.GroupLayout addStockPanelLayout = new org.jdesktop.layout.GroupLayout(addStockPanel);
        addStockPanel.setLayout(addStockPanelLayout);
        addStockPanelLayout.setHorizontalGroup(
            addStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(addStockPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(addStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(addDescriptionLabel)
                    .add(addStockPanelLayout.createSequentialGroup()
                        .add(addStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(addManufacturerLabel)
                            .add(addNameLabel)
                            .add(addSupplierLabel))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(addStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, addNameTF)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, addManufacturerTF)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, addStockPanelLayout.createSequentialGroup()
                                .add(addSupplierTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 143, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(addFindSupplierButton)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(addShowSupplierButton))
                    .add(addItemDescriptionLabel)
                    .add(addItemDescriptionTA1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(addStockPanelLayout.createSequentialGroup()
                        .add(addPriceLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(addPriceSP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 75, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(addPriceLabel1)))
                .addContainerGap())
            .add(org.jdesktop.layout.GroupLayout.TRAILING, addStockPanelLayout.createSequentialGroup()
                .addContainerGap(310, Short.MAX_VALUE)
                .add(addAddButton)
                .addContainerGap())
            .add(addStockPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(addStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(addStockPanelLayout.createSequentialGroup()
                        .add(addLocationLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(addLumberYardRB)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(addHardwareStoreRB))
                    .add(addStockLabel)
                    .add(addStockPanelLayout.createSequentialGroup()
                        .add(addMinStockLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(addMinStockSP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 78, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(addMaxStockLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(addMaxStockSP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 74, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(136, Short.MAX_VALUE))
        );
        addStockPanelLayout.setVerticalGroup(
            addStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(addStockPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(addDescriptionLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(addStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(addNameTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(addNameLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(addStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(addManufacturerLabel)
                    .add(addManufacturerTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(12, 12, 12)
                .add(addStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(addSupplierLabel)
                    .add(addSupplierTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(addFindSupplierButton)
                    .add(addShowSupplierButton))
                .add(9, 9, 9)
                .add(addItemDescriptionLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(addItemDescriptionTA1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(addStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(addPriceLabel)
                    .add(addPriceSP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(addPriceLabel1))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(addStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(addLocationLabel)
                    .add(addLumberYardRB)
                    .add(addHardwareStoreRB))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(addStockLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(addStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(addMinStockLabel)
                    .add(addMinStockSP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(addMaxStockLabel)
                    .add(addMaxStockSP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 112, Short.MAX_VALUE)
                .add(addAddButton)
                .addContainerGap())
        );

        stockTabbedPane.addTab("Tilføj", addStockPanel);

        findDescriptionLabel.setText("Her kan der søges på lageret");

        findNameLabel.setText("Navn:");

        findManufacturerLabel.setText("Producent:");

        findSupplierLabel.setText("Leverandør:");

        findFindSupplierButton.setText("Find");
        findFindSupplierButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findFindSupplierButtonActionPerformed(evt);
            }
        });

        findShowSupplierButton.setText("Info");
        findShowSupplierButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findShowSupplierButtonActionPerformed(evt);
            }
        });

        findPriceLabel.setText("Pris:");

        findPriceLabel1.setText("kr.");

        findLocationBG.add(findLumberYardRB);
        findLumberYardRB.setText("Trælasthandel");

        findLocationBG.add(findHardwareStoreRB);
        findHardwareStoreRB.setText("Byggemarked");

        findStockLabel.setText("Lager:");

        findMinStockLabel.setText("Min.");

        findMaxStockLabel.setText("Max.");

        findFindButton.setText("Søg");
        findFindButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findFindButtonActionPerformed(evt);
            }
        });

        showAllButton.setText("Vis alle");
        showAllButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showAllButtonActionPerformed(evt);
            }
        });

        findTable.setModel(new ItemTableModel());
        jScrollPane2.setViewportView(findTable);

        org.jdesktop.layout.GroupLayout findStockPanelLayout = new org.jdesktop.layout.GroupLayout(findStockPanel);
        findStockPanel.setLayout(findStockPanelLayout);
        findStockPanelLayout.setHorizontalGroup(
            findStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(findStockPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(findStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(findStockPanelLayout.createSequentialGroup()
                        .add(findStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(findStockPanelLayout.createSequentialGroup()
                                .add(findLumberYardRB)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(findHardwareStoreRB))
                            .add(findDescriptionLabel)
                            .add(findStockPanelLayout.createSequentialGroup()
                                .add(findStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(findNameLabel)
                                    .add(findSupplierLabel)
                                    .add(findManufacturerLabel))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(findStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                    .add(findManufacturerTF)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, findStockPanelLayout.createSequentialGroup()
                                        .add(findSupplierTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(findFindSupplierButton))
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, findNameTF)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, findStockPanelLayout.createSequentialGroup()
                                        .add(findPriceSP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 75, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(findPriceLabel1)))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(findShowSupplierButton))
                            .add(findPriceLabel))
                        .addContainerGap(50, Short.MAX_VALUE))
                    .add(findStockPanelLayout.createSequentialGroup()
                        .add(findStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(findStockPanelLayout.createSequentialGroup()
                                .add(findStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(findStockLabel)
                                    .add(findStockPanelLayout.createSequentialGroup()
                                        .add(findMinStockLabel)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                        .add(findMinStockSP, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE)
                                        .add(18, 18, 18)
                                        .add(findMaxStockLabel)
                                        .add(10, 10, 10)
                                        .add(findMaxStockSP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 75, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                                .add(123, 123, 123))
                            .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 355, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(findStockPanelLayout.createSequentialGroup()
                                .add(findFindButton)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(showAllButton)))
                        .add(120, 120, 120))))
        );
        findStockPanelLayout.setVerticalGroup(
            findStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(findStockPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(findDescriptionLabel)
                .add(findStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(findStockPanelLayout.createSequentialGroup()
                        .add(12, 12, 12)
                        .add(findNameLabel))
                    .add(findStockPanelLayout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(findNameTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(findStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(findManufacturerTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(findManufacturerLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(findStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(findSupplierTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(findSupplierLabel)
                    .add(findFindSupplierButton)
                    .add(findShowSupplierButton))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(findStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(findPriceLabel)
                    .add(findPriceSP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(findPriceLabel1))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(findStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(findLumberYardRB)
                    .add(findHardwareStoreRB))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(findStockLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(findStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(findMinStockLabel)
                    .add(findMinStockSP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(findMaxStockLabel)
                    .add(findMaxStockSP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(findStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(findFindButton)
                    .add(showAllButton))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 106, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(131, Short.MAX_VALUE))
        );

        stockTabbedPane.addTab("Søg", findStockPanel);

        getDescriptionLabel.setText("Her søges på et varenummer");

        getIdLabel.setText("ID:");

        getButton.setText("Søg");
        getButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                getButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout getStockPanelLayout = new org.jdesktop.layout.GroupLayout(getStockPanel);
        getStockPanel.setLayout(getStockPanelLayout);
        getStockPanelLayout.setHorizontalGroup(
            getStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(getStockPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(getStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(getDescriptionLabel)
                    .add(getStockPanelLayout.createSequentialGroup()
                        .add(getIdLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(getIdSp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(getButton))
                .addContainerGap(226, Short.MAX_VALUE))
        );
        getStockPanelLayout.setVerticalGroup(
            getStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(getStockPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(getDescriptionLabel)
                .add(18, 18, 18)
                .add(getStockPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(getIdLabel)
                    .add(getIdSp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(34, 34, 34)
                .add(getButton)
                .addContainerGap(361, Short.MAX_VALUE))
        );

        stockTabbedPane.addTab("Hent", getStockPanel);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, stockTabbedPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(stockTabbedPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void getButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_getButtonActionPerformed
		Item item = this.controller.getItem(Integer.parseInt(getIdSp.getValue().toString()));
		if(item != null)
		{
			new ItemInfoView(item).setVisible(true);
		}
		else
		{
			JOptionPane.showMessageDialog(this, "Der er angivet et forkert ID.", "Forkert ID", JOptionPane.ERROR_MESSAGE);
		}
	}//GEN-LAST:event_getButtonActionPerformed

	private void findFindButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findFindButtonActionPerformed
		Location location = null;
		if(addLumberYardRB.isSelected())
		{
			location = Location.LumberYard;
		}
		else
		{
			location = Location.HardwareStore;
		}
		int minimumStock = Integer.parseInt(findMinStockSP.getValue().toString());
		int maximumStock = Integer.parseInt(findMaxStockSP.getValue().toString());
		findTable.setModel(
			new ItemTableModel(
				this.controller.findItem(
									findNameTF.getText(),
									null,
									findManufacturerTF.getText(),
									this.supplierTemp,
									Double.parseDouble(findPriceSP.getValue().toString()),
									null,
									location,
									minimumStock,
									maximumStock)));
	}//GEN-LAST:event_findFindButtonActionPerformed

	private void addFindSupplierButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_addFindSupplierButtonActionPerformed
	{//GEN-HEADEREND:event_addFindSupplierButtonActionPerformed
		sp = new SupplierPicker();
		sp.addWindowListener(this);
		sp.setVisible(true);
}//GEN-LAST:event_addFindSupplierButtonActionPerformed

	private void addShowSupplierButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_addShowSupplierButtonActionPerformed
	{//GEN-HEADEREND:event_addShowSupplierButtonActionPerformed
		new SupplierInfoView(this.supplierTemp);
}//GEN-LAST:event_addShowSupplierButtonActionPerformed

	private void addAddButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_addAddButtonActionPerformed
	{//GEN-HEADEREND:event_addAddButtonActionPerformed
		if (!addNameTF.getText().equals("") && !addManufacturerTF.getText().equals("") && (!addSupplierTF.getText().equals("")))
		{
			Location location = null;
			if(addLumberYardRB.isSelected())
			{
				location = Location.LumberYard;
			}
			else
			{
				location = Location.HardwareStore;
			}
			int minimumStock = Integer.parseInt(addMinStockSP.getValue().toString());
			int maximumStock = Integer.parseInt(addMaxStockSP.getValue().toString());
			this.controller.addItem(addNameTF.getText(), addDescriptionTA.getText(), addManufacturerTF.getText(), this.supplierTemp, Double.parseDouble(addPriceSP.getValue().toString()), location, minimumStock, maximumStock);
			JOptionPane.showMessageDialog(this, "'"+addNameTF.getText()+"' er oprettet i databasen.", "Vare oprettet", JOptionPane.INFORMATION_MESSAGE);
			this.supplierTemp = null;
			addNameTF.setText("");
			addDescriptionTA.setText("");
			addManufacturerTF.setText("");
			addSupplierTF.setText("");
			findSupplierTF.setText("");
			addPriceSP.setValue(0);
			addMinStockSP.setValue(0);
			addMaxStockSP.setValue(0);
		}
		else
		{
			JOptionPane.showMessageDialog(this, "For at oprette en vare skal navn og producent udfyldes.", "Fejl i oprettelse", JOptionPane.WARNING_MESSAGE);
		}
	}//GEN-LAST:event_addAddButtonActionPerformed

	private void findShowSupplierButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findShowSupplierButtonActionPerformed
		sp = new SupplierPicker();
		sp.addWindowListener(this);
		sp.setVisible(true);
}//GEN-LAST:event_findShowSupplierButtonActionPerformed

	private void findFindSupplierButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findFindSupplierButtonActionPerformed
		new SupplierInfoView(this.supplierTemp);
}//GEN-LAST:event_findFindSupplierButtonActionPerformed

	private void showAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showAllButtonActionPerformed
		findTable.setModel(new ItemTableModel(this.controller.getAllItems()));
}//GEN-LAST:event_showAllButtonActionPerformed

	public void windowClosing(WindowEvent e)
	{
		if(sp != null)
		{
			this.supplierTemp = sp.getChosenSupplier();
			addSupplierTF.setText(this.supplierTemp.getName());
			findSupplierTF.setText(this.supplierTemp.getName());
		}
	}

	public void windowOpened(WindowEvent e) {}
	public void windowClosed(WindowEvent e) {}
	public void windowIconified(WindowEvent e) {}
	public void windowDeiconified(WindowEvent e) {}
	public void windowActivated(WindowEvent e) {}
	public void windowDeactivated(WindowEvent e) {}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addAddButton;
    private javax.swing.JLabel addDescriptionLabel;
    private javax.swing.JTextArea addDescriptionTA;
    private javax.swing.JButton addFindSupplierButton;
    private javax.swing.JRadioButton addHardwareStoreRB;
    private javax.swing.JLabel addItemDescriptionLabel;
    private javax.swing.JScrollPane addItemDescriptionTA1;
    private javax.swing.ButtonGroup addLocationBG;
    private javax.swing.JLabel addLocationLabel;
    private javax.swing.JRadioButton addLumberYardRB;
    private javax.swing.JLabel addManufacturerLabel;
    private javax.swing.JTextField addManufacturerTF;
    private javax.swing.JLabel addMaxStockLabel;
    private javax.swing.JSpinner addMaxStockSP;
    private javax.swing.JLabel addMinStockLabel;
    private javax.swing.JSpinner addMinStockSP;
    private javax.swing.JLabel addNameLabel;
    private javax.swing.JTextField addNameTF;
    private javax.swing.JLabel addPriceLabel;
    private javax.swing.JLabel addPriceLabel1;
    private javax.swing.JSpinner addPriceSP;
    private javax.swing.JButton addShowSupplierButton;
    private javax.swing.JLabel addStockLabel;
    private javax.swing.JPanel addStockPanel;
    private javax.swing.JLabel addSupplierLabel;
    private javax.swing.JTextField addSupplierTF;
    private javax.swing.JLabel findDescriptionLabel;
    private javax.swing.JButton findFindButton;
    private javax.swing.JButton findFindSupplierButton;
    private javax.swing.JRadioButton findHardwareStoreRB;
    private javax.swing.ButtonGroup findLocationBG;
    private javax.swing.JRadioButton findLumberYardRB;
    private javax.swing.JLabel findManufacturerLabel;
    private javax.swing.JTextField findManufacturerTF;
    private javax.swing.JLabel findMaxStockLabel;
    private javax.swing.JSpinner findMaxStockSP;
    private javax.swing.JLabel findMinStockLabel;
    private javax.swing.JSpinner findMinStockSP;
    private javax.swing.JLabel findNameLabel;
    private javax.swing.JTextField findNameTF;
    private javax.swing.JLabel findPriceLabel;
    private javax.swing.JLabel findPriceLabel1;
    private javax.swing.JSpinner findPriceSP;
    private javax.swing.JButton findShowSupplierButton;
    private javax.swing.JLabel findStockLabel;
    private javax.swing.JPanel findStockPanel;
    private javax.swing.JLabel findSupplierLabel;
    private javax.swing.JTextField findSupplierTF;
    private javax.swing.JTable findTable;
    private javax.swing.JButton getButton;
    private javax.swing.JLabel getDescriptionLabel;
    private javax.swing.JLabel getIdLabel;
    private javax.swing.JSpinner getIdSp;
    private javax.swing.JPanel getStockPanel;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JButton showAllButton;
    private javax.swing.JTabbedPane stockTabbedPane;
    // End of variables declaration//GEN-END:variables
}